package cn.dzhang.spring.boot.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;

/**
 * 用户角色
 *
 * @author dzhang
 * @since 2015年10月31日
 */
@Entity
@Table(name = "tbl_role")
public class Role extends ModelBase {

	private static final long serialVersionUID = -6617705663007904302L;
	@Column(nullable = false, length = 50)
	@Size(min = 2, max = 50)
	private String name;

	@ManyToMany
	@JoinTable(name = "tbl_user_role", joinColumns = @JoinColumn(name = "tbl_role_id"), inverseJoinColumns = @JoinColumn(name = "tbl_user_id"))
	private List<User> users;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	@Override
	public String toString() {
		return String.format("Role [name=%s]", name);
	}
}
